package com.example.yijian.edit.view.popup;

import android.content.Context;
import android.view.Gravity;
import android.view.animation.Animation;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.TranslateAnimation;

import com.example.yijian.R;

import razerdp.basepopup.BasePopupWindow;

public class BaseCommonPopupWindow extends BasePopupWindow {
    public BaseCommonPopupWindow(Context context) {
        super(context);
        setBackgroundColor(context.getResources().getColor(R.color.colorTranslucent));
        setPopupGravity(Gravity.BOTTOM);
        setShowAnimation(createTranslateAnimation(0, 0, 1f, 0));
        setDismissAnimation(createTranslateAnimation(0, 0, 0, 1f));
        setBackPressEnable(true);
    }

    private Animation createTranslateAnimation(float fromX, float toX, float fromY, float toY) {
        Animation animation = new TranslateAnimation(Animation.RELATIVE_TO_SELF,
                fromX,
                Animation.RELATIVE_TO_SELF,
                toX,
                Animation.RELATIVE_TO_SELF,
                fromY,
                Animation.RELATIVE_TO_SELF,
                toY);
        animation.setDuration(200);
        animation.setInterpolator(new DecelerateInterpolator());
        return animation;
    }

}
